package cn.tedu.charging.device.dao.repository.Impl;


import cn.tedu.charging.device.dao.mapper.ChargingStationMapper;
import cn.tedu.charging.device.dao.mapper.GunInfoMapper;
import cn.tedu.charging.device.dao.mapper.PileInfoMapper;
import cn.tedu.charging.device.dao.repository.DeviceRepository;
import cn.tedu.charging.device.pojo.po.ChargingGunInfoPO;
import cn.tedu.charging.device.pojo.po.ChargingPileInfoPO;
import cn.tedu.charging.device.pojo.po.StationPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;


@Slf4j
@Repository
public class DeviceRepositoryImpl implements DeviceRepository {
    @Autowired
    private GunInfoMapper gunInfoMapper;
    @Autowired
    PileInfoMapper pileInfoMapper;
    @Autowired
    ChargingStationMapper chargingStationMapper;
    @Override
    public Boolean updateGunStatus(ChargingGunInfoPO chargingGunInfoPO) {
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.eq("id",chargingGunInfoPO.getId());
        int row=gunInfoMapper.update(chargingGunInfoPO,updateWrapper);
        log.debug("更新枪状态:目标值:{},条件:{},影响行数:{}",chargingGunInfoPO,updateWrapper,row);
        if (row>0){
            return true;
        }
        return false;
    }

    @Override
    public ChargingGunInfoPO selectFromGunInfo(Integer gunId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",gunId);
        ChargingGunInfoPO chargingGunInfoPO = gunInfoMapper.selectOne(queryWrapper);

        return chargingGunInfoPO;
    }

    @Override
    public ChargingPileInfoPO selectFromPile(Integer pileId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",pileId);
        ChargingPileInfoPO chargingPileInfoPO = pileInfoMapper.selectOne(queryWrapper);

        return chargingPileInfoPO;
    }

    @Override
    public StationPO selectFromStation(Integer stationId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",stationId);
        StationPO stationPO = chargingStationMapper.selectOne(queryWrapper);
        return stationPO;
    }

    @Override
    public List<StationPO> getAllStation() {
        List<StationPO> list=chargingStationMapper.selectList(null);
        return list;
    }
}
